package com.ruoyi.shop.buying.task;

import com.ruoyi.shop.buying.service.impl.GroupBuyingServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ClickCountSyncTask {

    @Autowired
    private GroupBuyingServiceImpl groupBuyingService;

    /**
     * 每5分钟同步一次点击数到数据库
     */
    @Scheduled(fixedRate = 300000)  // 300000ms = 5分钟
    public void syncClickCount() {
        try {
            log.info("开始执行定时点击数同步任务");
            groupBuyingService.syncClickCountToDb();
            log.info("定时点击数同步任务执行完成");
        } catch (Exception e) {
            log.error("定时点击数同步任务执行失败", e);
        }
    }

    /**
     * 每天凌晨1点执行一次全量同步
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void fullSync() {
        try {
            log.info("开始执行每日全量点击数同步");
            groupBuyingService.syncClickCountToDb();
            log.info("每日全量点击数同步完成");
        } catch (Exception e) {
            log.error("每日全量点击数同步失败", e);
        }
    }
} 